
#ifndef _VIDEO_ENCODER_H_
#define _VIDEO_ENCODER_H_

#include <theora/theora.h>
#include <theora/theoraenc.h>
#include "def.h"

class VideoEncoder
{
public:
	VideoEncoder(const int fps, const int vWidth, const int vHeight, const int quality, 
		const int bitrate, const int keyframeshift, const int dropframe, const int fastmode);
	~VideoEncoder(void);

	PacketList*			headerPackets();
	PacketList*			encodeRGB(const unsigned char *data, int last = 0);
	PacketList*			remainPackets();

	int					videoWidth();
	int					videoHeight();

private:
	th_enc_ctx*			m_lpEncoderContext;
	th_info*			m_lpEncoderInfo;
	PacketList*			m_lpHeaderPackets;

	void				initTheoraInfo();
	void				initTheoraEncoder();
	void				uinitTheoraEncoder();

	PacketList*			createPacketList(int last = 0);

	int					createYCbCrBufferFromRGB(const unsigned char *data, th_ycbcr_buffer &buffer);
	void				freeYCbCrBuffer(th_ycbcr_buffer buffer);
	void				rgb_to_yuv444(int w, int h, const unsigned char *rgb, unsigned char *y, unsigned char *u, unsigned char *v);

	int					m_nFps;
	int					m_nVideoWidth;
	int					m_nVideoHeight;
	int					m_nQuality;
	int					m_nBitRate;
	int					m_nKeyFrameShift;
	int					m_bDropFrame;
	int					m_bFastMode;
};

#endif // _VIDEO_ENCODER_H_